package test;

import java.util.Scanner;

public class TriangleChecker {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入第一条边的长度：");
        double side1 = scanner.nextDouble();
        System.out.print("请输入第二条边的长度：");
        double side2 = scanner.nextDouble();
        System.out.print("请输入第三条边的长度：");
        double side3 = scanner.nextDouble();
        if (isTriangleValid(side1, side2, side3)) {
            System.out.println("能够构成三角形");
        } else {
            System.out.println("不能构成三角形");
        }
    }
    public static boolean isTriangleValid(double side1, double side2, double side3) {
        // 三角形任意两边之和大于第三边
        if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1) {
            return false;
        }
        // 三角形任意两边之差小于第三边
        if (Math.abs(side1 - side2) >= side3 || Math.abs(side1 - side3) >= side2 || Math.abs(side2 - side3) >= side1) {
            return false;
        }
        return true;
    }
}